<?php
/**
 * Utility class for uninstalling aLinks
 *
 * Copyright (C) 2008  Sean Hickey
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author Sean Hickey <sean@headzoo.com>
 * @version $Id: Uninstall.php 384 2008-07-03 05:32:27Z sean $
 * @package Alinks_Uninstall
 */
class Alinks_Uninstall
{
	/**
	 * Completely uninstalls aLinks
	 *
	 * @return bool
	 */
	public static function uninstall()
	{
		$wpdb = Alinks_Registry::get('wpdb');
		$table_prefix = Alinks_Registry::get('table_prefix');
		$plugin_basename = Alinks_Registry::get('plugin_basename');
		
		$wpdb->query("DROP TABLE IF EXISTS `{$table_prefix}alinks_keyphrases`");
		$wpdb->query("DROP TABLE IF EXISTS `{$table_prefix}alinks_k_options`");
		$wpdb->query("DROP TABLE IF EXISTS `{$table_prefix}alinks_settings`");
		
		$current = get_option('active_plugins');
		array_splice($current, array_search($plugin_basename, $current), 1);
		update_option('active_plugins', $current);
		do_action('deactivate_' . trim($plugin_basename));
	
		wp_redirect('plugins.php?deactivate=true');
		die();
	}
}